// pages/UserStatistics/Userindex/UserIndex.js
const controllers = require('../../controllers/controllerIndex.js').controller;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // status:-1,
    time:false,	 
    pay: false,
    activeIndex:0,
    tabs: [
      {
        name: "全部",
        // type: 0,
        vip:null,//是否vip
        // isActive: true
      },
      {
        name: "普通用户",
        // type: 1,
        vip: 0,//是否vip
        // isActive: false
      },
      {
        name: "普通会员",
        // type: 1,
        vip: 2,//是否vip
        // isActive: false
      },
      {
        name: "VIP会员",
        // type: 2,
        vip: 1,//是否vip
        // isActive: false
      }
    ]
  },
  seletBalance(){
    let pay=this.data.pay;
    this.setData({
      pay:pay?false:true,
      isTime:false
    })
    this.getUserList()
  },
  seletTime(){
    let time=this.data.time;
    this.setData({
      time:time?false:true,
      isTime:true
    })
    this.getUserList()
  },
  getUserList(){
    let that =this
    let time =this.data.time
    let pay =this.data.pay
    let isTime=this.data.isTime
    let params={
    sessionId: wx.getStorageSync('token'),
    shopId:wx.getStorageSync('shopId'),
    
   
  }

  if(isTime){
    params.time=time?"DESC":"ASC" 
  }else{
    params.pay=pay?"DESC":"ASC"
  }

  let item = this.data.tabs[this.data.activeIndex];
  if(null!=item.vip){
    params.vip = item.vip;
  }
  

  // if(this.data.status!=-1){
  //   params.vip=that.data.status	
  // }
  controllers.accountList(
    params
  ).then(res =>{
    that.setData({
      userList:res.data
    })
  })
  },

  clikcTabs(e) {
    const   index   = e.currentTarget.dataset.index
    
    this.setData({
      activeIndex:index
    });
    // let tabs = this.data.tabs
    
    // tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    // this.setData({
    //   tabs,
    //   status:index-1
    // })
      this.getUserList()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserList();
  },
  clikcDetails(res) {
   
    wx.navigateTo({
      url: '../UserDeatils/UserDeatils?id='+ res.currentTarget.dataset.id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})